<template>
  <div class="search">
    <f-drawer :title="modalTitle" ref="versionDrawer" :width="900" @submit="handleSubmit" @visibleChange="visibleChange">
      <version-form ref="form1" v-if="drawerVisible"></version-form>
    </f-drawer>
  </div>
</template>
<script>
  import VersionForm from './version_form'

  export default {
    name: 'versionDrawer',
    props: {},
    data() {
      return {
        isEdit: false,
        title: '',
        drawerVisible: false,
        current: 'form1',
        roleName: '',
        formData: {},
        forms: [
          'form1'
        ]
      }
    },
    methods: {
      handleShow(data) {
        this.isEdit = false
        if (data && data.versionId) {
          this.isEdit = true
          this.formData = data
        } else {
          this.formData = {}
        }
        this.$refs.versionDrawer.show()
        this.handleTabClick('form1')
      },
      handleSubmit(callback) {
        this.$refs[this.current].handleSubmit(callback)
      },
      visibleChange(drawerVisible) {
        this.drawerVisible = drawerVisible
      },
      handleTabClick(name) {
        this.current = name
        if (this.current === this.forms[0]) {
          this.title = this.isEdit ? '编辑版本' : '添加版本'
        }
        this.$nextTick(() => {
          this.$refs[this.current].setData(this.formData)
        })
      }
    },
    computed: {
      modalTitle: function() {
        return this.title
      }
    },
    created() {

    },
    components: { VersionForm }
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>


